using AjeeleeCms.Core.Common;
using AjeeleeCms.Web.Plugin.Feedback.BLL;
using AjeeleeCms.Web.Plugin.Feedback.Model;
using System;
using System.Text;
using System.Web;
using System.Web.SessionState;
namespace AjeeleeCms.Web.Plugin.Feedback
{
	public class ajax : IHttpHandler, IRequiresSessionState
	{
		public bool IsReusable
		{
			get
			{
				return false;
			}
		}
		public void ProcessRequest(HttpContext context)
		{
			string queryString = DTRequest.GetQueryString("action");
			string text = queryString;
			if (text != null)
			{
				if (text == "add")
				{
					this.feedback_add(context);
				}
			}
		}
		private void feedback_add(HttpContext context)
		{
			StringBuilder stringBuilder = new StringBuilder();
			AjeeleeCms.Web.Plugin.Feedback.BLL.feedback feedback = new AjeeleeCms.Web.Plugin.Feedback.BLL.feedback();
			AjeeleeCms.Web.Plugin.Feedback.Model.feedback feedback2 = new AjeeleeCms.Web.Plugin.Feedback.Model.feedback();
			string formString = DTRequest.GetFormString("txtCode");
			string formString2 = DTRequest.GetFormString("txtTitle");
			string formString3 = DTRequest.GetFormString("txtContent");
			string formString4 = DTRequest.GetFormString("txtUserName");
			string formString5 = DTRequest.GetFormString("txtUserTel");
			string formString6 = DTRequest.GetFormString("txtUserQQ");
			string formString7 = DTRequest.GetFormString("txtUserEmail");
			if (string.IsNullOrEmpty(formString))
			{
				context.Response.Write("{msg:0, msgbox:\"对不起，请输入验证码！\"}");
			}
			else
			{
				if (context.Session["dt_session_code"] == null)
				{
					context.Response.Write("{msg:0, msgbox:\"对不起，系统找不到生成的验证码！\"}");
				}
				else
				{
					if (formString.ToLower() != context.Session["dt_session_code"].ToString().ToLower())
					{
						context.Response.Write("{msg:0, msgbox:\"您输入的验证码与系统的不一致！\"}");
					}
					else
					{
						if (string.IsNullOrEmpty(formString3))
						{
							context.Response.Write("{msg: 0, msgbox: \"对不起，请输入留言的内容！\"}");
						}
						else
						{
							feedback2.title = formString2;
							feedback2.content = Utils.ToHtml(formString3);
							feedback2.user_name = formString4;
							feedback2.user_tel = formString5;
							feedback2.user_qq = formString6;
							feedback2.user_email = formString7;
							feedback2.add_time = DateTime.Now;
							feedback2.is_lock = 1;
							if (feedback.Add(feedback2) > 0)
							{
								context.Response.Write("{msg: 1, msgbox: \"恭喜您，留言提交成功啦！\"}");
							}
							else
							{
								context.Response.Write("{msg: 0, msgbox: \"对不起，保存过程中发生错误！\"}");
							}
						}
					}
				}
			}
		}
	}
}
